package com.example.plat.controller;

import com.example.plat.enity.Activity;
import com.example.plat.enity.dto.TipDto;
import com.example.plat.service.TipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Api(description = "获取最近的活动")
@RestController
@RequestMapping("/tip")
public class TipController {

    @Autowired
    ModelMapper mapper;

    @Autowired
    private TipService service;

    @ApiOperation("获取近三天活动")
    @GetMapping
    public ResponseEntity<List<TipDto>> getTip(Long userId){
        List<Activity> tip = service.getTip(userId);
        List<TipDto> dtos = tip.stream().map(u ->
                mapper.map(u, TipDto.class)
        ).collect(Collectors.toList());
        return ResponseEntity.ok(dtos);
    }

    @ApiOperation("获取近三天活动数量")
    @GetMapping("/{userId}")
    public ResponseEntity<Integer> getRecentNum(@ApiParam("用户ID")@PathVariable Long userId){
        Integer num = service.getRecentNum(userId);
        return ResponseEntity.ok(num);
    }
}
